# 基本使用
try:
    f = open("asd.txt", "r")
except:
    print("打开文件,出现异常了\n")

# 捕获指定异常
try:
    print(name)
except NameError as e:
    print("出现了变量未定义的异常")
    print(e, "\n")

# 捕获多个异常
try:
    # 1/0
    print(name)
except (NameError, ZeroDivisionError) as e:
    print(e, "\n")

"""
捕获全部异常 与下面这段代码效果一样
try:
    f = open("asd.txt", "r")
except:
    print("打开文件,出现异常了\n")
"""

try:
    print(age)
except Exception as e:
    print(e)

# 异常else用法 以及finally

try:
    # print(1/10)
    print(1 / 0)
except Exception as e:
    print(e)
else:
    print("没有出现异常")
finally:
    print("不管有没有异常都会执行finally")
